/*
* Poppy Game Engine - https://pgetemplate.googlecode.com/svn/
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* Copyright (c) 2008 Poppy
*/

#include "stdafx.h"
#include "CFPSTimer.h"

namespace PGESystem
{

	CFPSTimer::CFPSTimer( float updateCycle ) : m_fUpdateCycle(updateCycle)
	{
		m_pDeltaTime = 0;
		m_dFrameCount = 0;
		m_fTimeCount = 0;
		m_fUpdateRate = 0;
		m_fFps = 0;
	}

	void CFPSTimer::SetDeltaTime( const float* time, TIME_UNIT unit, const PGE_TICK_RESOLUTION* tickresolu, const PGE_CURRENT_TICK* deltatick )
	{

		m_pDeltaTime = time;
		switch(unit)
		{
		case MSEL:
			m_fUpdateRate = 1000.0f/m_fUpdateCycle;
			break;
		case SEC:
			m_fUpdateRate = 1.0f/m_fUpdateCycle;
			break;
		case MICRO:
			m_fUpdateRate = 1000000.0f/m_fUpdateCycle;
			break;
		}

	}

	bool CFPSTimer::ProcessPerTime()
	{
		m_fTimeCount += (*m_pDeltaTime);
		++m_dFrameCount;
		if(m_fTimeCount >= m_fUpdateCycle)
		{
			m_fFps = m_dFrameCount * m_fUpdateRate;
			m_dFrameCount = 0;
			m_fTimeCount = 0;
		}
		return false;
	}

	const float* CFPSTimer::GetFps() const
	{
		return &m_fFps;
	}

}
